<template>
    <!-- 添加或修改统计数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <el-col :span="12">
                            <el-form-item label="${comment}" prop="delFlag">
                                <el-input v-model="form.delFlag" placeholder="请输入${comment}"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="${comment}" prop="remark">
                                <el-input v-model="form.remark" placeholder="请输入${comment}"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="部门ID" prop="deptId">
                                <el-input v-model="form.deptId" placeholder="请输入部门ID"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="部门名称" prop="deptName">
                                <el-input v-model="form.deptName" placeholder="请输入部门名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="用户ID" prop="userId">
                                <el-input v-model="form.userId" placeholder="请输入用户ID"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="用户名称" prop="userName">
                                <el-input v-model="form.userName" placeholder="请输入用户名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="统计模块" prop="category">
                                <el-input v-model="form.category" placeholder="请输入统计模块"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="统计科目" prop="kind">
                                <el-input v-model="form.kind" placeholder="请输入统计科目"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count">
                                <el-input v-model="form.count" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money">
                                <el-input v-model="form.money" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数据生成时间" prop="insertTime">
                                <el-date-picker clearable
                                                v-model="form.insertTime"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择数据生成时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count1">
                                <el-input v-model="form.count1" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money1">
                                <el-input v-model="form.money1" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count2">
                                <el-input v-model="form.count2" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money2">
                                <el-input v-model="form.money2" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count3">
                                <el-input v-model="form.count3" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money3">
                                <el-input v-model="form.money3" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count4">
                                <el-input v-model="form.count4" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money4">
                                <el-input v-model="form.money4" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count5">
                                <el-input v-model="form.count5" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money5">
                                <el-input v-model="form.money5" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count6">
                                <el-input v-model="form.count6" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money6">
                                <el-input v-model="form.money6" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count7">
                                <el-input v-model="form.count7" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money7">
                                <el-input v-model="form.money7" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count8">
                                <el-input v-model="form.count8" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money8">
                                <el-input v-model="form.money8" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数量" prop="count9">
                                <el-input v-model="form.count9" placeholder="请输入数量"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="金额" prop="money9">
                                <el-input v-model="form.money9" placeholder="请输入金额"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "GoodsStatisticsForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/goodsStatistics/goodsStatistics/',
                    add:'/goodsStatistics/goodsStatistics/add',
                    edit:'/goodsStatistics/goodsStatistics/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
            id: null,
            createBy: null,
            createTime: null,
            updateBy: null,
            updateTime: null,
            delFlag: null,
            remark: null,
            deptId: null,
            deptName: null,
            userId: null,
            userName: null,
            category: null,
            kind: null,
            type: null,
            count: null,
            money: null,
            insertTime: null,
            count1: null,
            money1: null,
            count2: null,
            money2: null,
            count3: null,
            money3: null,
            count4: null,
            money4: null,
            count5: null,
            money5: null,
            count6: null,
            money6: null,
            count7: null,
            money7: null,
            count8: null,
            money8: null,
            count9: null,
            money9: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加统计数据";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改统计数据";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
